package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppWechatStep;
import com.ruoyi.background.service.IAppWechatStepService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户微信步数记录Controller
 *
 * @author susu
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/applet/appStep")
public class AppWechatStepController extends BaseController {
    @Autowired
    private IAppWechatStepService appWechatStepService;

    /**
     * 查询用户微信步数记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppWechatStep appWechatStep) {
        startPage();
        List<AppWechatStep> list = appWechatStepService.selectAppWechatStepList(appWechatStep);
        return getDataTable(list);
    }

    /**
     * 导出用户微信步数记录列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:export')")
    @Log(title = "用户微信步数记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppWechatStep appWechatStep) {
        List<AppWechatStep> list = appWechatStepService.selectAppWechatStepList(appWechatStep);
        ExcelUtil<AppWechatStep> util = new ExcelUtil<AppWechatStep>(AppWechatStep.class);
        util.exportExcel(response, list, "用户微信步数记录数据");
    }

    /**
     * 获取用户微信步数记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(appWechatStepService.selectAppWechatStepById(id));
    }

    /**
     * 新增用户微信步数记录
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:add')")
    @Log(title = "用户微信步数记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppWechatStep appWechatStep) {
        return toAjax(appWechatStepService.insertAppWechatStep(appWechatStep));
    }

    /**
     * 修改用户微信步数记录
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:edit')")
    @Log(title = "用户微信步数记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppWechatStep appWechatStep) {
        return toAjax(appWechatStepService.updateAppWechatStep(appWechatStep));
    }

    /**
     * 删除用户微信步数记录
     */
    @PreAuthorize("@ss.hasPermi('applet:appStep:remove')")
    @Log(title = "用户微信步数记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(appWechatStepService.deleteAppWechatStepByIds(ids));
    }
}
